package com.neuedu.service.impl;

import java.util.List;

import com.neuedu.dao.IGoodDAO;
import com.neuedu.dao.ITypeDAO;
import com.neuedu.dao.impl.GoodDAOImp;
import com.neuedu.dao.impl.TypeDAOImp;
import com.neuedu.entity.Goods;
import com.neuedu.entity.Type;
import com.neuedu.page.Page;
import com.neuedu.service.IGoodsService;
import com.neuedu.entity.Type;
public class GoodsServiceImp implements IGoodsService{

	private IGoodDAO gooddao=new GoodDAOImp();
	private ITypeDAO typedao=new TypeDAOImp();
	@Override
	public Page getPageGoods(int currentpage) {
		Page page=new Page();
		page.setPageNum(3);
		page.setCount(gooddao.selectCount(0));
		page.setCurrentpage(currentpage);
		
		List<Goods> listgoods=gooddao.selectAll(0, (page.getCurrentpage()-1)*page.getPageNum(), page.getPageNum());
		page.setData(listgoods);
		return page;
	}

	@Override
	public String ModifyType(Integer tid) {
		
		return null;
		
		
	}

	@Override
	public List<Type> getAllType() {
		List<Type> listtype=typedao.selectAll(0);
		return listtype;
	}

	@Override
	public Page getByName(String gname, int current) {
		Page page=new Page();
		page.setPageNum(3);
		page.setCount(gooddao.selectCount(gname,0));
		page.setCurrentpage(current);
		
		List<Goods> listgoods=gooddao.selectByName(gname,0, (page.getCurrentpage()-1)*page.getPageNum(), page.getPageNum());
		page.setData(listgoods);
		return page;
		
	}

	@Override
	public Page getByTypeId(Integer tid, int current) {
		Page page=new Page();
		page.setPageNum(3);
		page.setCount(gooddao.selectCount(tid,0));
		page.setCurrentpage(current);
		
		List<Goods> listgoods=gooddao.selectByTypeId(tid,0, (page.getCurrentpage()-1)*page.getPageNum(), page.getPageNum());
		page.setData(listgoods);
		return page;
	}

}
